package com.caixy.adminSystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.caixy.adminSystem.common.ErrorCode;
import com.caixy.adminSystem.exception.BusinessException;
import com.caixy.adminSystem.exception.ThrowUtils;
import com.caixy.adminSystem.mapper.FileTypeMapper;
import com.caixy.adminSystem.model.entity.FileType;
import com.caixy.adminSystem.service.FileTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.io.File;
@Service
public class FileTypeImpl extends ServiceImpl<FileTypeMapper, FileType>
        implements FileTypeService {


    @Override
    public void check(FileType fileType, Boolean add) {
        if (fileType==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
//        无参
        if (add){
            ThrowUtils.throwIf(StringUtils.isAnyBlank(fileType.getDescription(),fileType.getName()),ErrorCode.PARAMS_ERROR);

        }
//        有参
        if (StringUtils.isNotBlank(fileType.getDescription())&&fileType.getDescription().length()>8192){
            
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"描述过长");
        }
        if (StringUtils.isNotBlank(fileType.getName())&&fileType.getName().length()>80){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"名字过长");
        }
    }
}
